home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209b.zip / octave-2.09 / SCRIPTS.ZIP / scripts / plot / contour.m < prev    next >
Text File  |  1997-07-10  |  3KB  |  88 lines

  1. ## Copyright (C) 1996 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## usage: contour (z, n, x, y)
  21. ##
  22. ## See also: plot, semilogx, semilogy, loglog, polar, mesh, contour,
  23. ##           bar, stairs, gplot, gsplot, replot, xlabel, ylabel, title
  24.  
  25. ## Author: jwe
  26.  
  27. function contour (z, n, x, y)
  28.  
  29.   if (nargin == 1)
  30.     n = 10;
  31.   endif
  32.  
  33.   ## XXX FIXME XXX -- these plot states should really just be set
  34.   ## temporarily, probably inside an unwind_protect block, but there is
  35.   ## no way to determine their current values.
  36.  
  37.   if (nargin == 1 || nargin == 2)
  38.     if (is_matrix (z))
  39.       gset nosurface;
  40.       gset contour;
  41.       gset cntrparam bspline;
  42.       command = sprintf ("gset cntrparam levels %d", n);
  43.       eval (command);
  44.       gset noparametric;
  45.       gset view 0, 0, 1, 1;
  46.       gsplot z w l 1;
  47.     else
  48.       error ("contour: argument must be a matrix");
  49.     endif
  50.   elseif (nargin == 4)
  51.     if (is_vector (x) && is_vector (y) && is_matrix (z))
  52.       xlen = length (x);
  53.       ylen = length (y);
  54.       if (xlen == rows (z) && ylen == columns (z))
  55.         if (rows (x) == 1)
  56.           x = x';
  57.         endif
  58.         len = 3 * ylen;
  59.         zz = zeros (xlen, len);
  60.         k = 1;
  61.         for i = 1:3:len
  62.           zz(:,i)   = x;
  63.           zz(:,i+1) = y(k) * ones (xlen, 1);
  64.           zz(:,i+2) = z(k,:)';
  65.           k++;
  66.         endfor
  67.         gset nosurface;
  68.         gset contour;
  69.         gset cntrparam bspline;
  70.         command = sprintf ("gset cntrparam levels %d", n);
  71.         eval (command);
  72.     gset parametric;
  73.         gset view 0, 0, 1, 1;
  74.     gsplot zz w l 1;
  75.       else
  76.         msg = "contour: rows (z) must be the same as length (x) and";
  77.         msg = sprintf ("%s\ncolumns (z) must be the same as length (y)", msg);
  78.         error (msg);
  79.       endif
  80.     else
  81.       error ("contour: x and y must be vectors and z must be a matrix");
  82.     endif
  83.   else
  84.     usage ("contour (z, levels, x, y)");
  85.   endif
  86.  
  87. endfunction
  88.